{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAFPRJREFUeJzt3X+MXeV95/H31z+oawjiRwbk4h/j\nIGScEOPYI0QhaqIAipNWQBSKqCataViNRLLZlJIEEyuqVoq1rdIUitSkmYQUd3Vlk7hkQWnSglw3\nCCV4dwYcMDVes3Q8HsfAFANtcFFM+O4f94wz2DP2zNx758cz75c0Ovc899xzvsfH+syZ5z7nnMhM\nJEnlmjPVBUiSWsugl6TCGfSSVDiDXpIKZ9BLUuEMekkqnEEvSYUz6CWpcAa9JBVu3lQXAPDOd74z\n29vbp7oMSZpRent7/y0z20613LQI+vb2dnp6eqa6DEmaUSJi/1iWs+tGkgpn0EtS4Qx6SSrctOij\nl6SRHD16lIGBAd54442pLmVKLViwgMWLFzN//vwJfd6glzRtDQwM8I53vIP29nYiYqrLmRKZycsv\nv8zAwADLly+f0DrK67qp1aC9HebMqU9rtamuSNIEvfHGG5x77rmzNuQBIoJzzz23ob9qyjqjr9Wg\nqwuOHKnP799fnwfo7Jy6uiRN2GwO+SGN/huUdUa/ceOvQn7IkSP1dkmapcoK+v7+8bVL0imcccYZ\nJ32/r6+PSy65ZFzrvPnmm9m2bdux+cHBQebPn883vvGNCdV4KmUF/dKl42uXpGngu9/9Lpdffjlb\ntmxpyfrLCvpNm2Dhwre3LVxYb5dUvhYOxvj5z3/OVVddxZo1a3jve9/Lgw8+eOy9N998k/Xr17Nq\n1SpuuOEGjlRdyL29vXzgAx9g7dq1fPjDH+bQoUMjrnvLli189atfZWBggIMHDzat5iFlBX1nJ3R3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X5JWxklS4mdZ1I0ka\nJ4Nekgpn0EtS4Qx6SSqcQS9JhTPoJalwBr0kFc6gl6TC/X9bgb3mfxR4EwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x20fedd9c668>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import operator\n",
    "\n",
    "# 已知分类的数据\n",
    "x1 = np.array([3,2,1])\n",
    "y1 = np.array([104,100,81])\n",
    "x2 = np.array([101,99,98])\n",
    "y2 = np.array([10,5,2])\n",
    "scatter1 = plt.scatter(x1,y1,c='r')\n",
    "scatter2 = plt.scatter(x2,y2,c='b')\n",
    "\n",
    "# 未知数据\n",
    "x = np.array([18])\n",
    "y = np.array([90])\n",
    "scatter3 = plt.scatter(x,y,c='k')\n",
    "\n",
    "\n",
    "#画图例\n",
    "plt.legend(handles=[scatter1,scatter2,scatter3],labels=['labelA','labelB','X'],loc='best')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 已知分类的数据\n",
    "x_data = np.array([[3,104],\n",
    "                   [2,100],\n",
    "                   [1,81],\n",
    "                   [101,10],\n",
    "                   [99,5],\n",
    "                   [81,2]])\n",
    "y_data = np.array(['A','A','A','B','B','B'])\n",
    "x_test = np.array([18,90])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算样本数量\n",
    "x_data_size = x_data.shape[0]\n",
    "x_data_size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[18, 90],\n",
       "       [18, 90],\n",
       "       [18, 90],\n",
       "       [18, 90],\n",
       "       [18, 90],\n",
       "       [18, 90]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 复制x_test\n",
    "np.tile(x_test, (x_data_size,1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 15, -14],\n",
       "       [ 16, -10],\n",
       "       [ 17,   9],\n",
       "       [-83,  80],\n",
       "       [-81,  85],\n",
       "       [-63,  88]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算x_test与每一个样本的差值\n",
    "diffMat = np.tile(x_test, (x_data_size,1)) - x_data\n",
    "diffMat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 225,  196],\n",
       "       [ 256,  100],\n",
       "       [ 289,   81],\n",
       "       [6889, 6400],\n",
       "       [6561, 7225],\n",
       "       [3969, 7744]], dtype=int32)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算差值的平方\n",
    "sqDiffMat = diffMat**2\n",
    "sqDiffMat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  421,   356,   370, 13289, 13786, 11713], dtype=int32)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 求和\n",
    "sqDistances = sqDiffMat.sum(axis=1)\n",
    "sqDistances"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 20.51828453,  18.86796226,  19.23538406, 115.27792503,\n",
       "       117.41379817, 108.2266141 ])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 开方\n",
    "distances = sqDistances**0.5\n",
    "distances"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 0, 5, 3, 4], dtype=int64)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 从小到大排序\n",
    "sortedDistances = distances.argsort()\n",
    "sortedDistances"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "classCount = {}\n",
    "# 设置k\n",
    "k = 5\n",
    "for i in range(k):\n",
    "    # 获取标签\n",
    "    votelabel = y_data[sortedDistances[i]]\n",
    "    # 统计标签数量\n",
    "    classCount[votelabel] = classCount.get(votelabel,0) + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'A': 3, 'B': 2}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "classCount"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('A', 3), ('B', 2)]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 根据operator.itemgetter(1)-第1个值对classCount排序，然后再取倒序\n",
    "sortedClassCount = sorted(classCount.items(),key=operator.itemgetter(1), reverse=True)\n",
    "sortedClassCount"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'A'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取数量最多的标签\n",
    "knnclass = sortedClassCount[0][0]\n",
    "knnclass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
